cc.Class({
	extends: cc.Component,

	properties: {
		realplayer: {
			default: null,
			type: cc.Node
		},
		topNode: {
			default: null,
			type: cc.Node
		},
		 
	},

	// LIFE-CYCLE CALLBACKS:

	onLoad() {
		
	
		/*cc.follow(第一个参数为cc.Node,第二个参数可选:cc.Rect)，返回cc.Action*/
		//Camera.node.runAction(cc.follow(this.realplayer));
		//camera执行动作跟随node
		//Camera.node.runAction(cc.follow(this.crush,new cc.Rect(-10,-10,20,20)));
		//node在Rect的矩形范围内镜头不跟随移动，将要出范围时镜头跟随移动


		//this.camera.node.setPosition(this.realplayer.x,this.realplayer.y);
		
		const sendData = {
			"TaskGuid": "slkdjflie09876",
			"DataType": "usergy",
			"userid": "1"
		}

		var CanvasNode = this.topNode;

		if (!CanvasNode) {
			cc.log('find Canvas error');
			return;
		}
		
		
		var that = this;

		
		var onResourceLoaded2 = function(errorMessage, loadedResource) {
			
			var newMyPrefab2 = cc.instantiate(loadedResource);

			CanvasNode.addChild(newMyPrefab2, 100);

			newMyPrefab2.setPosition(0, 0);
			
			var newMyPrefabScript = newMyPrefab.getComponent('Warehouse');
			newMyPrefabScript.setShowClose(false);//不显示对话框关闭按钮
			
			newMyPrefabScript.onConfirBtn(function() {
				console.log("选择仓库按钮" + event.name);

			}.bind(this));


		};


		//获取网络数据
		let xhr = new XMLHttpRequest();
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
				var response = xhr.responseText;
				cc.log(response);
				let info = eval('(' + response + ')');
				let infores = eval('(' + info + ')');

				//cc.log(response);
				
				stepstatus = infores.status;
				
				if (infores.set.code == 2 || step == 2) {

					step = 2;
					//anim.resume('step1');
				
					waittime = infores.setlog.waittime;
					waitminutes = infores.setlog.waitminutes;
				} else if (infores.set.code == 3 || step == 3) {
					step = 3;
					//anim.resume('step1');
					waittime = infores.setlog.waittime;
					waitminutes = infores.setlog.waitminutes;
					//stepstatus = infores.status;

					
				} else if (infores.set.code == 4 || step == 4) {
					step = 4;
					//anim.resume('step1');
					waittime = infores.setlog.waittime;
					waitminutes = infores.setlog.waitminutes;
					//stepstatus = infores.status;

					

				} else if (infores.set.code == 5 || step == 5) {
					step = 5;
					//anim.resume('step1');
					waittime = infores.setlog.waittime;
					waitminutes = infores.setlog.waitminutes;
					//stepstatus = infores.status;

					
				} else if (infores.set.code == 6 || step == 6) {
					step = 6;
					//anim.resume('step1');
					waittime = infores.setlog.waittime;
					waitminutes = infores.setlog.waitminutes;
					//stepstatus = infores.status;

				} else if (infores.set.code == 7 ||step == 7) {
					step = 7;
					//anim.resume('step1');
					waittime = infores.setlog.waittime;
					waitminutes = infores.setlog.waitminutes;
					//stepstatus = infores.status;



				} else if (infores.set.code == 8 || step == 8) {
					step = 8;
					//anim.resume('step1');
					waittime = infores.setlog.waittime;
					waitminutes = infores.setlog.waitminutes;
					//stepstatus = infores.status;

				} else if (infores.set.code == 9 || step == 9) {
					step = 9;
					cc.log(step);
					//anim.resume('step1');
					waittime = infores.setlog.waittime;
					waitminutes = infores.setlog.waitminutes;
					//stepstatus = infores.status;



				} else {

					if (infores.status == 0) {
						var onResourceLoaded = function(errorMessage, loadedResource) {
							if (errorMessage) {
								cc.log('Prefab error:' + errorMessage);
								return;
							}
							if (!(loadedResource instanceof cc.Prefab)) {
								cc.log('Prefab error');
								return;
							}


							var newMyPrefab = cc.instantiate(loadedResource);

							CanvasNode.addChild(newMyPrefab, 100);

							newMyPrefab.setPosition(0, 0);

							var newMyPrefabScript = newMyPrefab.getComponent('Alert');

							newMyPrefabScript.setLabelString("您来了？那事不宜迟，\n先开始酿造您的第一款酒吧！");
							newMyPrefabScript.setShowClose(false);//不显示对话框关闭按钮
							newMyPrefabScript.onConfirBtn(function() {
								
								 step=2;
								 
								 
								 if(isShow==0){
								 	isShow=!isShow;
								 	cc.resources.load('Warehouse', onResourceLoaded2);
								 }
								 
								 
								 
							});
						};


					if(isShow==0){
						isShow=1;
						cc.resources.load('Alert', onResourceLoaded);
						}

						//===============================



					} else {


					}


				}



			}
		};

		// xhr.open("GET", seturl+'/'+JSON.stringify(sendData), true);
		xhr.open("GET", url + JSON.stringify(sendData), true);
		xhr.send();

	},




	start() {

	},

	// update (dt) {},
});
